package com.zx.flow.api.execute.request;

import com.zx.flow.api.util.ValidUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable;
import lombok.Data;
import org.springframework.validation.BindingResult;

@Data
public class BaseForm implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "请求异常信息")
    private String errorMsg = "";

    public boolean valid() {
        return true;
    }

    public final boolean valid(BindingResult result) {
        //  校验异常
        if (result.hasErrors()) {
            this.errorMsg = ValidUtil.getError(result);
            return false;
        }
        // 校验自定义的校验条件
        return valid();
    }

}